import * as types from '@/store/mutation-types'
import { getRandom } from '@/api/imges/images'

/**
 * @Description : Vuex---->actions
 * @author : August_xiao 1932794922@qq.com
 * @date : 2022-02-27 15:48
 */
const actions = {
  /**
   * //改变默认错误图片接口方法
   * @param context
   * @param payload
   */
  [types.CHANGED_EFAULT_ERROR_IMAGE_URL](context, payload) {
    //用户不传,这发送请求获取
    if (payload) {
      getRandom(payload)
        .then((res) => {
          const array = []
          array.push(res.data.pictureUrl)
          context.commit('CHANGED_EFAULT_ERROR_IMAGE_URL', array)
        })
        .catch(() => {
          // console.log(err)
        })
    } else {
      context.commit('CHANGED_EFAULT_ERROR_IMAGE_URL', payload)
    }
  },

  /**
   * 缓存动态路由
   * @param context
   * @param payload
   */
  [types.SET_NAV_ROUTE](context, payload) {
    // 这里是为了防止重复获取
    if (context.state.navList.length) return
    context.commit('SET_NAV_ROUTE', payload)
  }
}
export default actions
